﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Admin_Admin_CapNhatDoiTacChiTiet : System.Web.UI.Page
{
   int id;
    protected void Page_Load(object sender, EventArgs e)
    {
        id = int.Parse(Request.QueryString.Get("id"));
        DataDSTableAdapters.DOITACTableAdapter dtadapter = new DataDSTableAdapters.DOITACTableAdapter();
        DataDS.DOITACDataTable dttable= dtadapter.DOITAC_LayDoiTacTheoId(id);
        if (!this.IsPostBack)
        {
            txtTenDoiTac.Text = (string)dttable.Rows[0]["TenDoiTac"];
            imgHinhAnh.ImageUrl = (string)dttable.Rows[0]["Logo"];
            
            txtMaThue.Text = (string)dttable.Rows[0]["MaThue"];
            txtDiaChi.Text = (string)dttable.Rows[0]["DiaChi"];
            txtDienThoai.Text = (string)dttable.Rows[0]["DienThoai"];
            txtNguoiDaiDien.Text = (string)dttable.Rows[0]["NguoiDaiDien"];
            txtWebSite.Text = (string)dttable.Rows[0]["Website"];
            txtTaiKhoanNganHang.Text = dttable.Rows[0]["MaTaiKhoan_NganHang"].ToString();
        }
    }
    protected void btnCapNhat_Click(object sender, EventArgs e)
    {
        int? kq=0;
        string imageFolder = ConfigurationSettings.AppSettings["IMAGE_FOLDER"];
        //goi ham kiem tra cac thong so nhap, neu hop le tien hanh
        //cap nhat
        DataDSTableAdapters.DOITACTableAdapter dtadapter = new DataDSTableAdapters.DOITACTableAdapter();
         
        if (fulHinhAnh.FileName == "")
            dtadapter.DOITAC_CapNhatThongTinDoiTac(id, txtTenDoiTac.Text, imgHinhAnh.ImageUrl, txtTaiKhoanNganHang.Text, txtMaThue.Text, txtDiaChi.Text, txtDienThoai.Text, txtNguoiDaiDien.Text, txtWebSite.Text, ref kq);
        else
        {
            string strFilename;
            dtadapter.DOITAC_CapNhatThongTinDoiTac(id, txtTenDoiTac.Text, imageFolder + fulHinhAnh.FileName, txtTaiKhoanNganHang.Text, txtMaThue.Text, txtDiaChi.Text, txtDienThoai.Text, txtNguoiDaiDien.Text, txtWebSite.Text, ref kq);
            strFilename = Server.MapPath(imageFolder + fulHinhAnh.FileName);
            fulHinhAnh.PostedFile.SaveAs(strFilename);
            
        }   
        if (kq == 0)
            Response.Write("<script>alert('Cập nhật đối tác thành công');location.href='Admin_XemDanhSachDoiTac.aspx';</script>");
        else
            Response.Write("<script>alert('Cập nhật đối tác không thành công');location.href='Admin_XemDanhSachDoiTac.aspx';</script>");
       
    }
}
